<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // map
      const arr = [1, 2, 3]
      Array.prototype.myMap = function (fn) {
        const arr = []
        for (let i = 0; i < this.length; i++) {
          arr.push(fn(this[i], i, this))
        }
        return arr
      }
      const arr1 = arr.myMap((item, index, array) => item + 10)
      console.log(arr1) //11 12 13

      // filter
      Array.prototype.myFilter = function (fn) {
        const arr = []
        for (let i = 0; i < this.length; i++) {
          fn(this[i], i, this) ? arr.push(this[i]) : ''
        }
        return arr
      }
      const arr2 = arr.myFilter((item, index, array) => item >= 2)
      console.log(arr2) //2 3
    </script>
  </body>
</html>
